package com.woniu.controller;

import com.woniu.entity.Result;
import com.woniu.entity.dto.UserFeedbackDTO;
import com.woniu.pojo.UserFeedback;
import com.woniu.service.UserFeedbackService;
import com.woniu.utils.BaseController;
import com.woniu.utils.SMSUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Ma.Lei
 * @description
 * @date 2022/12/29 19:27
 */
@RestController
@RequestMapping("/UserFeedbackController")
@Api(tags = "用户意见反馈控制类")
public class UserFeedbackController extends BaseController {

    @Autowired
    private UserFeedbackService userFeedbackService;

    @ApiOperation("新增用户反馈")
    @PostMapping("/addUserFeedback")
    public Result addUserFeedback(@RequestBody UserFeedbackDTO userFeedbackDTO){
           if (userFeedbackDTO.getFeedbackContent() == null||userFeedbackDTO.getFeedbackContent().trim().length()==0){
               return new Result(500,"请输入意见反馈内容");
           }
           UserFeedback userFeedback = new UserFeedback();
           userFeedback.setUserId(userFeedbackDTO.getUserId());
           userFeedback.setFeedbackContent(userFeedbackDTO.getFeedbackContent());
           String randomNum = SMSUtils.getRandomNum(19);
           userFeedback.setFeedbackCode(randomNum);
           userFeedback.setFeedbackImage(userFeedbackDTO.getFeedbackImage());
           userFeedback.setPhone(userFeedbackDTO.getPhone());
           boolean flag = userFeedbackService.save(userFeedback);
           return toResult(flag);
    }
}
